#!/usr/bin/env python
#coding=utf-8

#refer to:http://www.daniweb.com/software-development/python/code/260268

import sys
import os
import wx

class myframe(wx.Frame):
    
    def __init__(self,parent,id,title):
        wx.Frame.__init__(self,parent,id,title)
        vbox=wx.BoxSizer(wx.VERTICAL)
        self.buttonrestart=wx.Button(self,-1,'restart me')
        self.Bind(wx.EVT_BUTTON,self.restart_program,self.buttonrestart)
        vbox.Add(self.buttonrestart,proportion=0,flag=0,border=5)
        self.SetSizer(vbox)
        self.Centre()
        
        pid=wx.GetProcessId()
        self.SetTitle('restart' + ' -- my pid:' + str(pid))
        
    def restart_program(self,evt):
        """Restarts the current program.
        Note: this function does not return. Any cleanup action (like
        saving data) must be done before calling this function."""
        python = sys.executable
        os.execl(python, python, * sys.argv)

if __name__ == "__main__":
    app=wx.App()
    frame=myframe(None,-1,'restart program')
    frame.Show()
    app.MainLoop()
